package com.sctvcloud.renhe.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.gridsum.tracker.GridsumWebDissector;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.renhe.R;
import com.sctvcloud.renhe.base.BaseActivity;
import com.sctvcloud.renhe.beans.FProgramme;
import com.sctvcloud.renhe.beans.NewsItem;
import com.sctvcloud.renhe.ui.activities.ReviewActivity;
import com.sctvcloud.renhe.ui.utils.GlideUtil;
import com.sctvcloud.renhe.ui.utils.SkipUtil;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/12 0012.
 */

public class AnchorColumnHolder extends BaseAnchorHolder<FProgramme> implements View.OnClickListener {
    @BindView(R.id.item_anchor_column_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_anchor_column_title)
    protected CustomFontTextView title;
    //    @BindView(R.id.item_anchor_column_lable)
//    protected CustomFontTextView lable;
    @BindView(R.id.item_anchor_column_playTime)
    protected CustomFontTextView playTime;
    @BindView(R.id.item_anchor_column_intro)
    protected CustomFontTextView intro;
    @BindView(R.id.item_anchor_column_update)
    protected CustomFontTextView update;
    @BindView(R.id.item_anchor_column_ll)
    protected LinearLayout latest_ll;
    @BindView(R.id.column_ll)
    protected LinearLayout column_ll;
    private String columnUrl;
    private NewsItem newsItem;
    private String showStr;


    public AnchorColumnHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(FProgramme fProgram) {
        if (fProgram != null) {
            column_ll.setVisibility(View.VISIBLE);
        }
        if (!TextUtils.isEmpty(fProgram.getProgramTitle())) {
            title.setText(fProgram.getProgramTitle());
        } else {
            title.setText("");
        }
//        if (!TextUtils.isEmpty(fProgram.getProgramType())) {
//            lable.setText(fProgram.getProgramType());
//        }
        String total = fProgram.getProgramTotal();
        String amout = fProgram.getPlayAmount();
        if (!TextUtils.isEmpty(total) && !TextUtils.equals("0", total)) {
            showStr = "总" + total + "期";
        }
        if (!TextUtils.isEmpty(amout) && !TextUtils.equals("0", amout)) {
            showStr = "播放" + amout + "次";
        }
        if (!TextUtils.isEmpty(total) && !TextUtils.equals("0", total) && !TextUtils.isEmpty(amout) && !TextUtils.equals("0", amout)) {
            showStr = "总" + total + "期" + "|" + "播放" + amout + "次";
        }
        playTime.setText(showStr);
        if (!TextUtils.isEmpty(fProgram.getProgramIntro())) {
            intro.setText(fProgram.getProgramIntro());
        } else {
            intro.setText("");
        }
        if (!TextUtils.isEmpty(fProgram.getUpdateInfo())) {
            update.setText("更新至:" + fProgram.getUpdateInfo());
        } else {
            update.setText("");
        }
        newsItem = fProgram.getProgramme();
        columnUrl = fProgram.getContentUrl();
        if (!TextUtils.isEmpty(fProgram.getProgramImage())) {
//            int pa = context.getResources().getDimensionPixelOffset(R.dimen.item_radius_size);
            GlideUtil.getGlideWith34DefNormal(context, fProgram.getProgramImage())
                    //  .transform(new GlideRoundTransformUtil(context, 5))
                    .into(img);
        } else {
            img.setImageResource(R.mipmap.icon_def_3_4);
        }
    }

    @OnClick(value = {R.id.item_anchor_column_ll})
    public void latestOnClick(View view) {
        pairs.add(new Pair<>("位置", "主持栏目"));
        if (fragment != null) {
            GridsumWebDissector.getInstance().trackEvent(fragment, "", newsItem.getNewsTitle(), "", 200, pairs);

        } else if (activity != null) {
            GridsumWebDissector.getInstance().trackEvent(activity, "", newsItem.getNewsTitle(), "", 200, pairs);

        }
        SkipUtil.skipWithNewsItem(context, newsItem, new HashMap<String, String>());
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(context, ReviewActivity.class);
        if (!TextUtils.isEmpty(columnUrl) && columnUrl.endsWith(".json")) {
            intent.putExtra(BaseActivity.EX_ID, columnUrl);
            context.startActivity(intent);
        } else {
            Toast.makeText(context, "url错误", Toast.LENGTH_SHORT).show();
        }
    }
}
